//
//  HomeFeatureCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/7/25.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit
import SDWebImage
import SVProgressHUD

class HomeFeatureCell: BaseTableViewCell {
    
    var isNewCity = false{
    
        didSet{
        
            if isNewCity == true {
                
                label1.isHidden = false
                label2.isHidden = true
                label3.isHidden = true
                label4.isHidden = false
                label5.isHidden = false
                imageView2.contentMode = .scaleAspectFit
                imageView2.image = UIImage(named: "timg")
                imageView3.contentMode = .scaleToFill
                imageView3.image = UIImage(named: "lodging")
                
                return
                
            }else{
                
                label1.isHidden = true
                label2.isHidden = true
                label3.isHidden = true
                label4.isHidden = true
                label5.isHidden = true
                
                
            }

        
        }
    
    
    }

    @IBOutlet weak var label1: UILabel!
    
    @IBOutlet weak var label2: UILabel!
    
    @IBOutlet weak var label3: UILabel!
    
    @IBOutlet weak var label4: UILabel!
    
    @IBOutlet weak var label5: UILabel!
    
    @IBOutlet weak var lineView1: UIView!
    
    @IBOutlet weak var lineView2: UIView!
    
    @IBOutlet weak var lineView3: UIView!
    
    
    @IBOutlet weak var bottomConstr: NSLayoutConstraint!
    
    @IBOutlet weak var imageView1: UIImageView!
    @IBOutlet weak var imageView2: UIImageView!
    @IBOutlet weak var imageView3: UIImageView!
    @IBOutlet weak var imageView4: UIImageView!
    @IBOutlet weak var imageView5: UIImageView!
    @IBOutlet weak var indicatorView1: UIActivityIndicatorView!
    @IBOutlet weak var indicatorView2: UIActivityIndicatorView!
    @IBOutlet weak var indicatorView3: UIActivityIndicatorView!
    @IBOutlet weak var indicatorView4: UIActivityIndicatorView!
    @IBOutlet weak var indicatorView5: UIActivityIndicatorView!
    
    
    
    
    
    var model : HomeOneGroup?{
        
        didSet{
            
                       
            indicatorView1.startAnimating()
            imageView1.sd_setImage(with: URL(string :model!.rectangle1_image), placeholderImage: UIImage.defaulImage(), options: []) { (image, _, _, _) in
                self.indicatorView1.stopAnimating()
                self.imageView1.contentMode = .scaleToFill
                
            }
            
            indicatorView2.startAnimating()
            imageView2.sd_setImage(with: URL(string :model!.rectangle2_image), placeholderImage: UIImage.defaulImage(), options: []) { (image, _, _, _) in
                self.indicatorView2.stopAnimating()
                self.imageView2.contentMode = .scaleToFill

                
            }
            
            indicatorView3.startAnimating()
            imageView3.sd_setImage(with: URL(string :model!.rectangle3_image  ), placeholderImage: UIImage.defaulImage(), options: []) { (image, _, _, _) in
                self.indicatorView3.stopAnimating()
                self.imageView3.contentMode = .scaleToFill

                
            }
            
            indicatorView4.startAnimating()
            imageView4.sd_setImage(with: URL(string :model!.rectangle4_image  ), placeholderImage: UIImage.defaulImage(), options: []) { (image, _, _, _) in
                self.indicatorView4.stopAnimating()
                self.imageView4.contentMode = .scaleToFill

                
            }
            
            indicatorView5.startAnimating()
            imageView5.sd_setImage(with: URL(string :model!.rectangle5_image  ), placeholderImage: UIImage.defaulImage(), options: []) { (image, _, _, _) in
                self.indicatorView5.stopAnimating()
                self.imageView5.contentMode = .scaleToFill

                
            }
            

            
            
            
            
            
            
            
            
            
            
            }
        
        
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        lineView1.backgroundColor = UIColor.lineGray()
        lineView2.backgroundColor = UIColor.lineGray()
        lineView3.backgroundColor = UIColor.lineGray()
        bottomConstr.constant = -8
        
        
        imageView1.contentMode = .center
        imageView2.contentMode = .center
        imageView3.contentMode = .center
        imageView4.contentMode = .center
        imageView5.contentMode = .center

        // Initialization code
    }
    
    
    
    
    
    
    @IBAction func btn1DidTap(_ sender: UIButton) {
        
        if isNewCity == true {
            
            SVProgressHUD.showInfo(withStatus: "此功能等待接入...")
            
        } else {
            
            jumpVC(type: model?.rectangle1_type, data: model?.rectangle1_data)
            
        }
        
    }
    
    
    @IBAction func btn2DidTap(_ sender: UIButton) {
        
        if isNewCity == true {
            viewController().navigationController?.pushViewController(NewCityNoticeVC(), animated: true)
        } else {
            
            jumpVC(type: model?.rectangle2_type, data: model?.rectangle2_data)
            
        }

        

        
    }
    
    
    @IBAction func btn3DidTap(_ sender: UIButton) {
        
        
        if isNewCity == true {
            
            viewController().navigationController?.pushViewController(HousesCarportRentVC(), animated: true)

            
        } else {
            
            jumpVC(type: model?.rectangle3_type, data: model?.rectangle3_data)
            
        }

        

        
    }
    
    
    
    @IBAction func btn4DidTap(_ sender: UIButton) {
        
        
        if isNewCity == true {
            SVProgressHUD.showInfo(withStatus: "此功能等待接入...")

        } else {
            
            jumpVC(type: model?.rectangle4_type, data: model?.rectangle4_data)
            
        }

        

        
        
    }
    
    
    @IBAction func btn5DidTap(_ sender: UIButton) {
        
        
        
        if isNewCity == true {
            SVProgressHUD.showInfo(withStatus: "此功能等待接入...")

        } else {
            
            jumpVC(type: model?.rectangle5_type, data: model?.rectangle5_data)
            
        }
        

        
    }
    
    
    
    
    
    func jumpVC(type : String?,data : String?) {
        
        
        if type == "keyword" {
            
            let temp = GoodsListController()
            
            temp.keyword = data
            
            viewController().navigationController?.pushViewController(temp, animated: true)
            
        } else {
            
            if type == "url" {
                
                if data!.contains("mall.xjscvip.com") {
                    
                    let temp = UpLoadIconController()
                    
                    
                    temp.urlStr = data ?? ""
                    
                    
                    viewController().navigationController?.pushViewController(temp, animated: true)
                    
                } else {
                    
                    let temp = UpLoadIconController()
                    
                    temp.hiddenBar = false
                    
                    temp.urlStr = data ?? ""
                    
                    
                    viewController().navigationController?.pushViewController(temp, animated: true)
                    
                }
                
                
                
            } else if type == "goods"{
                
                let temp = GoodsDetailController()
                
                temp.urlStr = data ?? ""
                
                viewController().navigationController?.pushViewController(temp, animated: true)
                
            }
            
            
            
        }
        
        
        
    }
    
    
    

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
